home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / system / DumpSector.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  2.0 KB  |  104 lines

  1. /***********************************************************************
  2. ***
  3. ***  CDTV Dump Sector 1.0 (26-SEP-90)
  4. ***
  5. ***    By CARL SASSENRATH, Ukiah, CA  (707)-462-4878
  6. ***
  7. ***    Free to Distribute amoung CDTV developers.
  8. ***
  9. ***    A simple CD-ROM reader that uses the device driver directly
  10. ***    to access data.
  11. ***
  12. ***********************************************************************/
  13.  
  14. #include <exec/types.h>
  15. #include <exec/io.h>
  16. #include "cd.h"
  17.  
  18. extern    struct    IOStdReq *CreateStdIO();
  19. extern    struct    MsgPort  *CreatePort();
  20. struct    IOStdReq *IORequest = NULL;
  21. struct    MsgPort  *IOPort = NULL;
  22. char    Buffer[2048];
  23. int    QuitFlag = FALSE;
  24.  
  25. #define    MUST(expr)  if (!(expr)) Quit();
  26.  
  27. main(argc,argv)
  28.     int argc;
  29.     char *argv[];
  30. {
  31.     int sector;
  32.  
  33.     if (argc < 2) sector = 16;
  34.     else
  35.     {
  36.         sector = atoi(argv[1]);
  37.         if (!sector) sector = 16;
  38.     }
  39.  
  40.     MUST(IOPort = CreatePort(0,0));
  41.     MUST(IORequest = CreateStdIO(IOPort));
  42.  
  43.     if (OpenDevice("cdtv.device",0,IORequest,0))
  44.         {printf("CDTV Device will not open\n");    Quit();}
  45.  
  46.     IORequest->io_Command = CD_READ;
  47.     IORequest->io_Offset = sector * 2048;
  48.     IORequest->io_Length = 2048;
  49.     IORequest->io_Data   = (APTR)Buffer;
  50.     if (DoIO(IORequest)) printf("READ command error\n");
  51.  
  52.     printf("CD-ROM SECTOR: %ld\n",sector);
  53.     DumpBlock(sector,Buffer,2048);
  54.  
  55.     Quit();
  56. }
  57.  
  58. Quit()
  59. {
  60.     if (IORequest->io_Device) CloseDevice(IORequest);
  61.     if (IORequest)    DeleteStdIO(IORequest);
  62.     if (IOPort)    DeletePort(IOPort);
  63. }
  64.  
  65. /* abort -- Capture MANX ^C interrupt */
  66. _abort()
  67. {
  68.     QuitFlag = TRUE;
  69. }
  70.  
  71. /* PrtChar -- Utility function used with DumpBlock */
  72. char PrtChar(c)
  73.     register char c;
  74. {
  75.     if (c < ' ' || c > '~') return '.';
  76.     return c;
  77. }
  78.  
  79. /* Bytes Per Line: */
  80. #define BPL 16
  81.  
  82. /* DumpBlock -- print a block of bytes */
  83. DumpBlock(blk,buf,size)
  84.     long blk;
  85.     unsigned char *buf;
  86.     long size;
  87. {
  88.     register int i,j;
  89.  
  90.     for (i = 0; i < size; i+=BPL )
  91.     {
  92.         if (QuitFlag) break;
  93.         printf("%03x:",i);    
  94.         for (j = 0; j < BPL; j++)
  95.         {
  96.             printf("%02x",buf[i+j]);
  97.             if (((j+1)%2) == 0) printf(" ");
  98.         }
  99.         for (j = 0; j < BPL; j++) printf("%c",PrtChar(buf[i+j]));
  100.         printf("\n");
  101.     }
  102.     printf("\n");
  103. }
  104.